using System;
using System.Collections;
using System.Collections.Generic;
using TEngine;
using UnityEngine;
using UnityEngine.EventSystems;
using UnityEngine.UI;

namespace GameLogic
{
    [Window(UILayer.UI, fullScreen: true)]
    public class Pan_GameMaze : UIWindow
    {
        #region UI Components
        [SerializeField] private Button m_btnClose; // 关闭按钮
        [SerializeField] private Button m_btnHit; // 提示按钮
        [SerializeField] private RectTransform m_rectMatrix; // 矩阵容器
        [SerializeField] private RectTransform m_rectTarget;
        private MatrixCtrl m_matrixCtrl; // 矩阵控制器
        private WindowAnimationHelper m_animationHelper; // 窗口动画辅助
        private EventTriggerListener m_eventTriggerListener;
        #endregion

        #region Lifecycle Methods
        protected override void BindMemberProperty()
        {
            m_btnClose = FindChildComponent<Button>("m_btnClose");
            m_btnHit = FindChildComponent<Button>("m_btnHit");
            m_rectMatrix = FindChildComponent<RectTransform>("GameView/m_rectMatrix");
            m_matrixCtrl = m_rectMatrix.gameObject.GetOrAddComponent<MatrixCtrl>();
            m_animationHelper = new WindowAnimationHelper(this);
            m_eventTriggerListener = EventTriggerListener.Get(gameObject);
        }

        protected override void RegisterEvent()
        {
            m_btnClose.onClick.AddListener(OnClose);
            m_btnHit.onClick.AddListener(OnOnHintClick);
            m_eventTriggerListener.OnClick += OnMatrixClick;
        }


        protected override void OnCreate()
        {
            m_animationHelper.Initialize();
        }

        protected override async void OnRefresh()
        {
            await m_animationHelper.PlayOpenAnimation();
        }

        protected override void OnDestroy()
        {
            m_animationHelper.Cleanup();
            m_btnClose.onClick.RemoveAllListeners();
            m_btnHit.onClick.RemoveAllListeners();
            base.OnDestroy();
        }
        #endregion

        #region Events
        private async void OnClose()
        {
            await m_animationHelper.PlayCloseAnimation();
            Close();
        }
        private void OnOnHintClick()
        {

        }

        private void OnMatrixClick(GameObject go, PointerEventData ev)
        {

        }
        #endregion
    }
}
